package com.designpattern.singleton;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @author libo
 * @ClassName SingletonTest
 * @Description: TODO（这里用一句话描述这个类的作用)
 * @date 2018/12/28 10:25
 */
public class SingletonTest {
    public static void main(String[] args) throws InterruptedException {
        Set<Singleton> set = new HashSet<>();
        Set<Singleton> singletonSet = Collections.synchronizedSet(set);
        for (int i = 0; i <1000 ; i++) {
            new Thread(()->{
                singletonSet.add(Singleton.getInstance());
            }).start();
        }
        Thread.sleep(10000);
        for (Singleton singleton : singletonSet) {
            System.out.println(singleton);
        }
    }
}
